package commands;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.Bucket;
import jesss.commands.JesssCommand;
import jesss.commands.JesssCommandFactoryImpl;
import jesss.options.JesssOptions;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

import static org.mockito.Mockito.*;

/**
 * User: Lee
 * Date: 8/21/13
 * Time: 11:20 PM
 */
public class ListBucketsCommandTests extends CommandTestsBase {

    private AmazonS3 mockS3 = mock(AmazonS3.class);
    private JesssOptions mockJesssOptions = mock(JesssOptions.class);

    @Before
    public void Setup() {
        stub(mockJesssOptions.getAmazonS3()).toReturn(mockS3);
        List<Bucket> testBuckets = makeTestBuckets(5);
        stub(mockS3.listBuckets()).toReturn(testBuckets);
        stub(mockJesssOptions.getCommandName()).toReturn("lbs");
        stub(mockJesssOptions.getShouldDisplayVerbose()).toReturn(true);
    }

    @Test
    public void CanListBuckets() throws Exception {
        JesssCommand listBucketsCommand = JesssCommandFactoryImpl.getInstance().createCommand(mockS3, mockJesssOptions.getCommandName(), mockJesssOptions.getShouldDisplayVerbose(), new String[0]);

        listBucketsCommand.executeCommand();
        verify(mockS3, times(1)).listBuckets();
    }
}
